<!DOCTYPE html>
<html lang="" xml:lang="">
<head>

  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title>2 Julia | 编程语言笔记</title>
  <meta name="description" content="2 Julia | 编程语言笔记" />
  <meta name="generator" content="bookdown 0.35 and GitBook 2.6.7" />

  <meta property="og:title" content="2 Julia | 编程语言笔记" />
  <meta property="og:type" content="book" />
  
  
  

  <meta name="twitter:card" content="summary" />
  <meta name="twitter:title" content="2 Julia | 编程语言笔记" />
  
  
  

<meta name="author" content="云腾足下" />



  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  
  
<link rel="prev" href="Maple.html"/>
<link rel="next" href="Stata.html"/>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.4.6/dist/fuse.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />








<link href="libs/anchor-sections-1.1.0/anchor-sections.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.1.0/anchor-sections-hash.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.1.0/anchor-sections.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  jax: ["input/TeX","output/SVG"],
  extensions: ["tex2jax.js","MathMenu.js","MathZoom.js"],
  TeX: {
    extensions: ["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"]
  }
});
</script>
<script type="text/javascript"
   src="../../../MathJax/MathJax.js">
</script>


<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {   }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>

<style type="text/css">
  
  div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
</style>

</head>

<body>



  <div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">

    <div class="book-summary">
      <nav role="navigation">

<ul class="summary">
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>序</a></li>
<li class="chapter" data-level="1" data-path="Maple.html"><a href="Maple.html"><i class="fa fa-check"></i><b>1</b> Maple</a>
<ul>
<li class="chapter" data-level="1.1" data-path="Maple.html"><a href="Maple.html#快捷键"><i class="fa fa-check"></i><b>1.1</b> 快捷键</a></li>
<li class="chapter" data-level="1.2" data-path="Maple.html"><a href="Maple.html#几个基本的代数处理"><i class="fa fa-check"></i><b>1.2</b> 几个基本的代数处理</a></li>
<li class="chapter" data-level="1.3" data-path="Maple.html"><a href="Maple.html#产生序列"><i class="fa fa-check"></i><b>1.3</b> 产生序列</a></li>
<li class="chapter" data-level="1.4" data-path="Maple.html"><a href="Maple.html#函数定义"><i class="fa fa-check"></i><b>1.4</b> 函数定义</a>
<ul>
<li class="chapter" data-level="1.4.1" data-path="Maple.html"><a href="Maple.html#参数的宣称"><i class="fa fa-check"></i><b>1.4.1</b> 参数的宣称</a></li>
</ul></li>
<li class="chapter" data-level="1.5" data-path="Maple.html"><a href="Maple.html#控制流"><i class="fa fa-check"></i><b>1.5</b> 控制流</a></li>
<li class="chapter" data-level="1.6" data-path="Maple.html"><a href="Maple.html#画图"><i class="fa fa-check"></i><b>1.6</b> 画图</a></li>
<li class="chapter" data-level="1.7" data-path="Maple.html"><a href="Maple.html#矩阵"><i class="fa fa-check"></i><b>1.7</b> 矩阵</a></li>
<li class="chapter" data-level="1.8" data-path="Maple.html"><a href="Maple.html#一句话tips"><i class="fa fa-check"></i><b>1.8</b> 一句话Tips</a></li>
</ul></li>
<li class="chapter" data-level="2" data-path="Julia.html"><a href="Julia.html"><i class="fa fa-check"></i><b>2</b> Julia</a>
<ul>
<li class="chapter" data-level="2.1" data-path="Julia.html"><a href="Julia.html#julia的一些体会"><i class="fa fa-check"></i><b>2.1</b> Julia的一些体会</a>
<ul>
<li class="chapter" data-level="2.1.1" data-path="Julia.html"><a href="Julia.html#关于函数的参数"><i class="fa fa-check"></i><b>2.1.1</b> 关于函数的参数</a></li>
</ul></li>
<li class="chapter" data-level="2.2" data-path="Julia.html"><a href="Julia.html#julia的一些常用包"><i class="fa fa-check"></i><b>2.2</b> Julia的一些常用包</a>
<ul>
<li class="chapter" data-level="2.2.1" data-path="Julia.html"><a href="Julia.html#优化包"><i class="fa fa-check"></i><b>2.2.1</b> 优化包</a></li>
<li class="chapter" data-level="2.2.2" data-path="Julia.html"><a href="Julia.html#julia数值求根"><i class="fa fa-check"></i><b>2.2.2</b> Julia数值求根</a></li>
<li class="chapter" data-level="2.2.3" data-path="Julia.html"><a href="Julia.html#dataframes包"><i class="fa fa-check"></i><b>2.2.3</b> <code>DataFrames</code>包</a></li>
</ul></li>
<li class="chapter" data-level="2.3" data-path="Julia.html"><a href="Julia.html#julia的ide体验"><i class="fa fa-check"></i><b>2.3</b> Julia的IDE体验</a></li>
<li class="chapter" data-level="2.4" data-path="Julia.html"><a href="Julia.html#其他tips"><i class="fa fa-check"></i><b>2.4</b> 其他tips</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="Stata.html"><a href="Stata.html"><i class="fa fa-check"></i><b>3</b> Stata</a>
<ul>
<li class="chapter" data-level="3.1" data-path="Stata.html"><a href="Stata.html#数据处理"><i class="fa fa-check"></i><b>3.1</b> 数据处理</a></li>
<li class="chapter" data-level="3.2" data-path="Stata.html"><a href="Stata.html#回归相关"><i class="fa fa-check"></i><b>3.2</b> 回归相关</a>
<ul>
<li class="chapter" data-level="3.2.1" data-path="Stata.html"><a href="Stata.html#描述性统计和回归结果导出"><i class="fa fa-check"></i><b>3.2.1</b> 描述性统计和回归结果导出</a></li>
</ul></li>
<li class="chapter" data-level="3.3" data-path="Stata.html"><a href="Stata.html#一些外部命令"><i class="fa fa-check"></i><b>3.3</b> 一些外部命令</a></li>
<li class="chapter" data-level="3.4" data-path="Stata.html"><a href="Stata.html#stata对某个变量随机抽样"><i class="fa fa-check"></i><b>3.4</b> stata对某个变量随机抽样</a></li>
<li class="chapter" data-level="3.5" data-path="Stata.html"><a href="Stata.html#stata调用r"><i class="fa fa-check"></i><b>3.5</b> Stata调用R</a></li>
<li class="chapter" data-level="3.6" data-path="Stata.html"><a href="Stata.html#miscellaneous"><i class="fa fa-check"></i><b>3.6</b> Miscellaneous</a></li>
</ul></li>
<li class="chapter" data-level="4" data-path="Matlab.html"><a href="Matlab.html"><i class="fa fa-check"></i><b>4</b> Matlab</a>
<ul>
<li class="chapter" data-level="4.1" data-path="Matlab.html"><a href="Matlab.html#一句话tips-1"><i class="fa fa-check"></i><b>4.1</b> 一句话Tips</a></li>
<li class="chapter" data-level="4.2" data-path="Matlab.html"><a href="Matlab.html#带名称和缺省值的参数设置"><i class="fa fa-check"></i><b>4.2</b> 带名称和缺省值的参数设置</a></li>
<li class="chapter" data-level="4.3" data-path="Matlab.html"><a href="Matlab.html#窗口输出到文本"><i class="fa fa-check"></i><b>4.3</b> 窗口输出到文本</a></li>
<li class="chapter" data-level="4.4" data-path="Matlab.html"><a href="Matlab.html#gvar-toolbox使用报告"><i class="fa fa-check"></i><b>4.4</b> GVAR Toolbox使用报告</a>
<ul>
<li class="chapter" data-level="4.4.1" data-path="Matlab.html"><a href="Matlab.html#数据输入"><i class="fa fa-check"></i><b>4.4.1</b> 数据输入</a></li>
<li class="chapter" data-level="4.4.2" data-path="Matlab.html"><a href="Matlab.html#模型设定"><i class="fa fa-check"></i><b>4.4.2</b> 模型设定</a></li>
<li class="chapter" data-level="4.4.3" data-path="Matlab.html"><a href="Matlab.html#一些坑"><i class="fa fa-check"></i><b>4.4.3</b> 一些坑</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="5" data-path="git操作流程.html"><a href="git操作流程.html"><i class="fa fa-check"></i><b>5</b> git操作流程</a>
<ul>
<li class="chapter" data-level="5.1" data-path="git操作流程.html"><a href="git操作流程.html#基本语法"><i class="fa fa-check"></i><b>5.1</b> 基本语法</a></li>
<li class="chapter" data-level="5.2" data-path="git操作流程.html"><a href="git操作流程.html#生成公钥"><i class="fa fa-check"></i><b>5.2</b> 生成公钥</a></li>
<li class="chapter" data-level="5.3" data-path="git操作流程.html"><a href="git操作流程.html#本地库操作"><i class="fa fa-check"></i><b>5.3</b> 本地库操作</a></li>
<li class="chapter" data-level="5.4" data-path="git操作流程.html"><a href="git操作流程.html#关联远程库码云"><i class="fa fa-check"></i><b>5.4</b> 关联远程库（码云）</a></li>
<li class="chapter" data-level="5.5" data-path="git操作流程.html"><a href="git操作流程.html#打开vi后的操作"><i class="fa fa-check"></i><b>5.5</b> 打开VI后的操作</a></li>
<li class="chapter" data-level="5.6" data-path="git操作流程.html"><a href="git操作流程.html#给递交进行标记"><i class="fa fa-check"></i><b>5.6</b> 给递交进行标记</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="C.html"><a href="C.html"><i class="fa fa-check"></i><b>6</b> C语言</a>
<ul>
<li class="chapter" data-level="6.1" data-path="C.html"><a href="C.html#一句话tips-2"><i class="fa fa-check"></i><b>6.1</b> 一句话Tips</a></li>
</ul></li>
<li class="chapter" data-level="7" data-path="Latex.html"><a href="Latex.html"><i class="fa fa-check"></i><b>7</b> Latex</a>
<ul>
<li class="chapter" data-level="7.1" data-path="Latex.html"><a href="Latex.html#一句话tips-3"><i class="fa fa-check"></i><b>7.1</b> 一句话Tips</a></li>
<li class="chapter" data-level="7.2" data-path="Latex.html"><a href="Latex.html#使用pdfpages包插入pdf页面"><i class="fa fa-check"></i><b>7.2</b> 使用<code>pdfpages</code>包插入PDF页面</a></li>
<li class="chapter" data-level="7.3" data-path="Latex.html"><a href="Latex.html#记录几个快捷键"><i class="fa fa-check"></i><b>7.3</b> 记录几个快捷键</a></li>
<li class="chapter" data-level="7.4" data-path="Latex.html"><a href="Latex.html#手动安装新的宏包"><i class="fa fa-check"></i><b>7.4</b> 手动安装新的宏包</a></li>
<li class="chapter" data-level="7.5" data-path="Latex.html"><a href="Latex.html#beamer相关"><i class="fa fa-check"></i><b>7.5</b> <code>beamer</code>相关</a></li>
<li class="chapter" data-level="7.6" data-path="Latex.html"><a href="Latex.html#表格相关"><i class="fa fa-check"></i><b>7.6</b> 表格相关</a>
<ul>
<li class="chapter" data-level="7.6.1" data-path="Latex.html"><a href="Latex.html#长表格"><i class="fa fa-check"></i><b>7.6.1</b> 长表格</a></li>
</ul></li>
<li class="chapter" data-level="7.7" data-path="Latex.html"><a href="Latex.html#章节标题格式修改"><i class="fa fa-check"></i><b>7.7</b> 章节标题格式修改</a></li>
<li class="chapter" data-level="7.8" data-path="Latex.html"><a href="Latex.html#数学公式相关"><i class="fa fa-check"></i><b>7.8</b> 数学公式相关</a>
<ul>
<li class="chapter" data-level="7.8.1" data-path="Latex.html"><a href="Latex.html#数学公式左对齐"><i class="fa fa-check"></i><b>7.8.1</b> 数学公式左对齐</a></li>
</ul></li>
<li class="chapter" data-level="7.9" data-path="Latex.html"><a href="Latex.html#中文字体加粗"><i class="fa fa-check"></i><b>7.9</b> 中文字体加粗</a></li>
<li class="chapter" data-level="7.10" data-path="Latex.html"><a href="Latex.html#使用某种常用字体"><i class="fa fa-check"></i><b>7.10</b> 使用某种常用字体</a>
<ul>
<li class="chapter" data-level="7.10.1" data-path="Latex.html"><a href="Latex.html#如何使用一个新的字体"><i class="fa fa-check"></i><b>7.10.1</b> 如何使用一个新的字体？</a></li>
</ul></li>
<li class="chapter" data-level="7.11" data-path="Latex.html"><a href="Latex.html#我的r代码排版模版"><i class="fa fa-check"></i><b>7.11</b> 我的R代码排版模版</a>
<ul>
<li class="chapter" data-level="7.11.1" data-path="Latex.html"><a href="Latex.html#listings包"><i class="fa fa-check"></i><b>7.11.1</b> <code>listings</code>包</a></li>
<li class="chapter" data-level="7.11.2" data-path="Latex.html"><a href="Latex.html#fancyvrb包"><i class="fa fa-check"></i><b>7.11.2</b> <code>fancyvrb</code>包</a></li>
</ul></li>
<li class="chapter" data-level="7.12" data-path="Latex.html"><a href="Latex.html#latex插入附录"><i class="fa fa-check"></i><b>7.12</b> latex插入附录</a></li>
<li class="chapter" data-level="7.13" data-path="Latex.html"><a href="Latex.html#latex参考文献的编码思路"><i class="fa fa-check"></i><b>7.13</b> latex参考文献的编码思路</a>
<ul>
<li class="chapter" data-level="7.13.1" data-path="Latex.html"><a href="Latex.html#参考文献较少的情况"><i class="fa fa-check"></i><b>7.13.1</b> 参考文献较少的情况</a></li>
<li class="chapter" data-level="7.13.2" data-path="Latex.html"><a href="Latex.html#参考文献较多的情况"><i class="fa fa-check"></i><b>7.13.2</b> 参考文献较多的情况</a></li>
<li class="chapter" data-level="7.13.3" data-path="Latex.html"><a href="Latex.html#如何将文献引用作为上标出现"><i class="fa fa-check"></i><b>7.13.3</b> 如何将文献引用作为上标出现？</a></li>
</ul></li>
<li class="chapter" data-level="7.14" data-path="Latex.html"><a href="Latex.html#一些文体的模版"><i class="fa fa-check"></i><b>7.14</b> 一些文体的模版</a>
<ul>
<li class="chapter" data-level="7.14.1" data-path="Latex.html"><a href="Latex.html#社科申报课题部分模版"><i class="fa fa-check"></i><b>7.14.1</b> 社科申报课题部分模版</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="8" data-path="Blog.html"><a href="Blog.html"><i class="fa fa-check"></i><b>8</b> 博客</a></li>
<li class="chapter" data-level="9" data-path="OS.html"><a href="OS.html"><i class="fa fa-check"></i><b>9</b> macOS操作系统</a>
<ul>
<li class="chapter" data-level="9.1" data-path="OS.html"><a href="OS.html#一句话tips-4"><i class="fa fa-check"></i><b>9.1</b> 一句话Tips</a></li>
<li class="chapter" data-level="9.2" data-path="OS.html"><a href="OS.html#安装和配置latex"><i class="fa fa-check"></i><b>9.2</b> 安装和配置Latex</a></li>
<li class="chapter" data-level="9.3" data-path="OS.html"><a href="OS.html#homebrew"><i class="fa fa-check"></i><b>9.3</b> Homebrew</a></li>
<li class="chapter" data-level="9.4" data-path="OS.html"><a href="OS.html#挂载外置磁盘"><i class="fa fa-check"></i><b>9.4</b> 挂载外置磁盘</a></li>
</ul></li>
<li class="chapter" data-level="10" data-path="Mathematica.html"><a href="Mathematica.html"><i class="fa fa-check"></i><b>10</b> Mathematica</a>
<ul>
<li class="chapter" data-level="10.1" data-path="Mathematica.html"><a href="Mathematica.html#快捷键-1"><i class="fa fa-check"></i><b>10.1</b> 快捷键</a></li>
</ul></li>
<li class="chapter" data-level="11" data-path="Python.html"><a href="Python.html"><i class="fa fa-check"></i><b>11</b> python</a>
<ul>
<li class="chapter" data-level="11.1" data-path="Python.html"><a href="Python.html#vscode下配置python"><i class="fa fa-check"></i><b>11.1</b> VSCode下配置python</a></li>
</ul></li>
<li class="chapter" data-level="12" data-path="Other.html"><a href="Other.html"><i class="fa fa-check"></i><b>12</b> 其他小众软件</a>
<ul>
<li class="chapter" data-level="12.1" data-path="Other.html"><a href="Other.html#pdf文件压缩"><i class="fa fa-check"></i><b>12.1</b> PDF文件压缩</a></li>
<li class="chapter" data-level="12.2" data-path="Other.html"><a href="Other.html#eviews编程"><i class="fa fa-check"></i><b>12.2</b> Eviews编程</a></li>
<li class="chapter" data-level="12.3" data-path="Other.html"><a href="Other.html#gauss"><i class="fa fa-check"></i><b>12.3</b> GAUSS</a>
<ul>
<li class="chapter" data-level="12.3.1" data-path="Other.html"><a href="Other.html#系统函数"><i class="fa fa-check"></i><b>12.3.1</b> 系统函数</a></li>
</ul></li>
<li class="chapter" data-level="12.4" data-path="Other.html"><a href="Other.html#zotero"><i class="fa fa-check"></i><b>12.4</b> Zotero</a></li>
<li class="chapter" data-level="12.5" data-path="Other.html"><a href="Other.html#word中插入公式"><i class="fa fa-check"></i><b>12.5</b> Word中插入公式</a>
<ul>
<li class="chapter" data-level="12.5.1" data-path="Other.html"><a href="Other.html#自带的公式输入"><i class="fa fa-check"></i><b>12.5.1</b> 自带的公式输入</a></li>
<li class="chapter" data-level="12.5.2" data-path="Other.html"><a href="Other.html#公式编号的其他方法"><i class="fa fa-check"></i><b>12.5.2</b> 公式编号的其他方法</a></li>
<li class="chapter" data-level="12.5.3" data-path="Other.html"><a href="Other.html#利用texsword编辑器"><i class="fa fa-check"></i><b>12.5.3</b> 利用TexsWord编辑器</a></li>
</ul></li>
<li class="chapter" data-level="12.6" data-path="Other.html"><a href="Other.html#noteexpress样式设置"><i class="fa fa-check"></i><b>12.6</b> NoteExpress样式设置</a></li>
<li class="chapter" data-level="12.7" data-path="Other.html"><a href="Other.html#filezilla"><i class="fa fa-check"></i><b>12.7</b> FileZilla</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="references.html"><a href="references.html"><i class="fa fa-check"></i>References</a></li>
</ul>

      </nav>
    </div>

    <div class="book-body">
      <div class="body-inner">
        <div class="book-header" role="navigation">
          <h1>
            <i class="fa fa-circle-o-notch fa-spin"></i><a href="./">编程语言笔记</a>
          </h1>
        </div>

        <div class="page-wrapper" tabindex="-1" role="main">
          <div class="page-inner">

            <section class="normal" id="section-">
<div id="Julia" class="section level1 hasAnchor" number="2">
<h1><span class="header-section-number">2</span> Julia<a href="Julia.html#Julia" class="anchor-section" aria-label="Anchor link to header"></a></h1>
<div id="julia的一些体会" class="section level2 hasAnchor" number="2.1">
<h2><span class="header-section-number">2.1</span> Julia的一些体会<a href="Julia.html#julia的一些体会" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p><strong>关于类型</strong>。Julia一些包会自己构造一些类型，我们很多时候需要访问这个类型的成员，但成员的名字往往并不事先知道。一般情况下，可以通过下面三种办法获知成员的名字：</p>
<ul>
<li><code>dump(类型)</code></li>
<li><code>fieldnames(类型)</code></li>
<li>在帮助系统查看这个类型的帮助</li>
</ul>
<div id="关于函数的参数" class="section level3 hasAnchor" number="2.1.1">
<h3><span class="header-section-number">2.1.1</span> 关于函数的参数<a href="Julia.html#关于函数的参数" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>参数本质上分两种，一种是按位置确认的参数。另一种是键值对参数。其按名字确认，位置随便。这两类参数在创造函数时要用分号隔开。</p>
<p>按位置确认的参数可以有默认值，记住这只是默认值，是不能按名字给它传参的。比如，</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode julia"><code class="sourceCode julia"><span id="cb10-1"><a href="Julia.html#cb10-1" tabindex="-1"></a><span class="kw">function</span> <span class="fu">addtwo</span>(x, y <span class="op">=</span> <span class="fl">1</span>)</span>
<span id="cb10-2"><a href="Julia.html#cb10-2" tabindex="-1"></a>  x <span class="op">+</span> y</span>
<span id="cb10-3"><a href="Julia.html#cb10-3" tabindex="-1"></a><span class="kw">end</span></span>
<span id="cb10-4"><a href="Julia.html#cb10-4" tabindex="-1"></a><span class="fu">addtwo</span>(<span class="fl">1</span>,<span class="fl">2</span>) <span class="co"># 正常</span></span>
<span id="cb10-5"><a href="Julia.html#cb10-5" tabindex="-1"></a><span class="fu">addtwo</span>(<span class="fl">1</span>, y <span class="op">=</span> <span class="fl">3</span>) <span class="co"># 报错,不能按名字传，除非是第二类键值对参数。</span></span></code></pre></div>
<p>类似于R语言中<code>...</code>，它也可以传这种参数，但它需要在<code>...</code>前加一个名称，如</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode julia"><code class="sourceCode julia"><span id="cb11-1"><a href="Julia.html#cb11-1" tabindex="-1"></a><span class="kw">function</span> <span class="fu">addtwo</span>(x, y <span class="op">=</span> <span class="fl">1</span>, z<span class="op">...</span>)</span>
<span id="cb11-2"><a href="Julia.html#cb11-2" tabindex="-1"></a>  x <span class="op">+</span> y</span>
<span id="cb11-3"><a href="Julia.html#cb11-3" tabindex="-1"></a>  <span class="fu">println</span>(z)</span>
<span id="cb11-4"><a href="Julia.html#cb11-4" tabindex="-1"></a>  <span class="fu">println</span>(z<span class="op">...</span>)</span>
<span id="cb11-5"><a href="Julia.html#cb11-5" tabindex="-1"></a><span class="kw">end</span></span></code></pre></div>
<p>函数体内可以直接调用<code>z</code>，但是此时的<code>z</code>是一个元组，很多时候我们需要把它展开，即以<code>z...</code>的形式调用。</p>
</div>
</div>
<div id="julia的一些常用包" class="section level2 hasAnchor" number="2.2">
<h2><span class="header-section-number">2.2</span> Julia的一些常用包<a href="Julia.html#julia的一些常用包" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<div id="优化包" class="section level3 hasAnchor" number="2.2.1">
<h3><span class="header-section-number">2.2.1</span> 优化包<a href="Julia.html#优化包" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p><code>Optim</code>包做单变量，多变量优化非常优秀，是最流行的一个优化包。比如我常用的单变量优化，里面就有黄金分割算法等。</p>
</div>
<div id="julia数值求根" class="section level3 hasAnchor" number="2.2.2">
<h3><span class="header-section-number">2.2.2</span> Julia数值求根<a href="Julia.html#julia数值求根" class="anchor-section" aria-label="Anchor link to header"></a></h3>
<p>对于单方程求根，可以使用两个包如下。这两个包可以找到既定区间下所有的根。代码案例如下，</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode julia"><code class="sourceCode julia"><span id="cb12-1"><a href="Julia.html#cb12-1" tabindex="-1"></a><span class="im">using</span> <span class="bu">IntervalArithmetic</span>, <span class="bu">IntervalRootFinding</span></span>
<span id="cb12-2"><a href="Julia.html#cb12-2" tabindex="-1"></a><span class="fu">f</span>(x) <span class="op">=</span> <span class="fu">sin</span>(x) <span class="op">-</span> <span class="fl">0.1</span><span class="op">*</span>x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> <span class="fl">1</span></span>
<span id="cb12-3"><a href="Julia.html#cb12-3" tabindex="-1"></a>a <span class="op">=</span> <span class="fu">roots</span>(f, <span class="op">-</span><span class="fl">10</span><span class="op">..</span><span class="fl">10</span>) <span class="co"># 第二个参数就是在`IntervalArithmetic`包中区间这个类型的表达方式</span></span>
<span id="cb12-4"><a href="Julia.html#cb12-4" tabindex="-1"></a>a[<span class="fl">1</span>].interval.lo <span class="co"># 返回第一个根的下界</span></span></code></pre></div>
<p>这里有几个注意的地方:第一，<code>roots</code>返回的是<code>Root</code>对象，可以通过前面说的方法，查看它的成员字段，知道它有两个字段一个是<code>interval</code>，一个是<code>status</code>。我们需要前者，然后<code>interval</code>本身又是一个类型，于是按照前面的方法继续查看它的字段，一个是<code>lo</code>，一个<code>hi</code>。</p>
</div>
<div id="dataframes包" class="section level3 hasAnchor" number="2.2.3">
<h3><span class="header-section-number">2.2.3</span> <code>DataFrames</code>包<a href="Julia.html#dataframes包" class="anchor-section" aria-label="Anchor link to header"></a></h3>
</div>
</div>
<div id="julia的ide体验" class="section level2 hasAnchor" number="2.3">
<h2><span class="header-section-number">2.3</span> Julia的IDE体验<a href="Julia.html#julia的ide体验" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<ul>
<li>Julia的一个IDE就是Atom中的Juno，它已经非常好用了。记录几个点：
<ul>
<li>快捷键配置，是在一个文件中修改的，见https://blog.csdn.net/uniqsa/article/details/91315714。这个给一个我常用的运行和保存配置书写,注意缩进：</li>
</ul></li>
</ul>
<pre><code>&#39;.platform-darwin atom-text-editor[data-grammar=&quot;source julia&quot;]&#39;:
  &#39;ctrl-enter&#39;: &#39;julia-client:run-block&#39;
  &#39;shift-ctrl-enter&#39;: &#39;julia-client:run-all&#39;

&#39;body&#39;:
  &#39;ctrl-s&#39;: &#39;core:save&#39;</code></pre>
<ul>
<li>VSCode这个IDE似乎更好用。记录几个快捷键备忘：
<ul>
<li><code>ctrl+enter</code>执行本行命令但光标不往下走</li>
<li><code>ctrl+shift</code>执行本行命令但光标往下走</li>
<li><code>cmd+M</code>激活终端，这个是我自己设的。后来我发现它有个缺省的`ctrl+``就是激活终端。</li>
<li><code>cmd+1/2/3</code>在不同组的pane间切换。</li>
<li><code>ctrl+1/2/3</code>激活第1/2/3个编辑器。</li>
<li><code>esc</code>清除本行代码运行结果</li>
<li><code>cmd+shift+p</code>调出命令面板，可以直接输命令执行</li>
<li>file菜单下可以打开文件夹，也可以打开工作空间。如果你只有一个项目，往往只需要打开文件夹，但如果你有多个项目同时运作，你可以保存为一个工作空间，然后以后以打开工作空间的形式来编辑代码。</li>
<li>查bug，要用那个带小虫子的按钮运行。</li>
</ul></li>
</ul>
</div>
<div id="其他tips" class="section level2 hasAnchor" number="2.4">
<h2><span class="header-section-number">2.4</span> 其他tips<a href="Julia.html#其他tips" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<ul>
<li>查看模块内都有些什么东西，用<code>names(MyModule)</code>，查看一个类里面都有什么东西，用<code>fieldnames(MyClass)</code>。</li>
<li>类似于R中<code>.rdata</code>的格式的数据保存，<code>JLD2</code>包的<code>jldsave("mydata.jld2")</code>使用。然后用<code>load("mydata.jld2")</code>来加载。</li>
<li>在Julia中变量按引用传递，举个例子如下。</li>
</ul>
<div class="sourceCode" id="cb14"><pre class="sourceCode julia"><code class="sourceCode julia"><span id="cb14-1"><a href="Julia.html#cb14-1" tabindex="-1"></a>a <span class="op">=</span> [<span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span>]</span>
<span id="cb14-2"><a href="Julia.html#cb14-2" tabindex="-1"></a>b <span class="op">=</span> a</span>
<span id="cb14-3"><a href="Julia.html#cb14-3" tabindex="-1"></a>a[<span class="fl">1</span>] <span class="op">=</span> <span class="fl">10</span> <span class="co"># 此时b的值也会变成10，如果你想让两个变量不一样，你应该上一句使用b=copy(a)</span></span></code></pre></div>
<ul>
<li>安装包</li>
</ul>
<div class="sourceCode" id="cb15"><pre class="sourceCode julia"><code class="sourceCode julia"><span id="cb15-1"><a href="Julia.html#cb15-1" tabindex="-1"></a><span class="im">import</span> <span class="bu">Pkg;</span></span>
<span id="cb15-2"><a href="Julia.html#cb15-2" tabindex="-1"></a><span class="bu">Pkg</span>.<span class="fu">add</span>(<span class="st">&quot;DataFrames&quot;</span>)</span>
<span id="cb15-3"><a href="Julia.html#cb15-3" tabindex="-1"></a><span class="co"># Pkg.rm()是删除包</span></span>
<span id="cb15-4"><a href="Julia.html#cb15-4" tabindex="-1"></a><span class="im">using</span> <span class="bu">DataFrames </span><span class="co"># 导入包</span></span></code></pre></div>
<ul>
<li><code>Pipe</code>包提供了强大的管道操作<code>|&gt;</code>，与R语言中的<code>.</code>不同，它使用<code>_</code>作为占位符。</li>
</ul>
<div class="sourceCode" id="cb16"><pre class="sourceCode julia"><code class="sourceCode julia"><span id="cb16-1"><a href="Julia.html#cb16-1" tabindex="-1"></a><span class="pp">@pipe</span> data <span class="op">|&gt;</span> <span class="fu">addX</span>(_[<span class="fl">1</span>],_[<span class="fl">2</span>]) <span class="op">|&gt;</span> println</span></code></pre></div>
<ul>
<li><code>1:5</code>返回的是一个迭代器，可以用<code>collect(1:5)</code>变成一个数组</li>
<li><code>using RCall, Statistics</code>可以同时导入多个包</li>
<li><code>mean(skipmissing([1, missing, 3]))</code>求均值忽略缺失值</li>
<li>查看模块中所有方法或变量<code>names(模块)</code>。通常是去github上看它的案例用法。</li>
<li>返回当前工作空间的变量，可以用<code>names(Main)</code>或者<code>varinfo()</code></li>
<li>函数名字中带‘！’号，该函数不仅返回值，还会更改参数的值。</li>
<li>在Julia表达式中，如果要标志某个字符是变量，也就是它要被它的内涵所替代，前面要加美元符号。比如定义一个宏：</li>
</ul>
<div class="sourceCode" id="cb17"><pre class="sourceCode julia"><code class="sourceCode julia"><span id="cb17-1"><a href="Julia.html#cb17-1" tabindex="-1"></a><span class="kw">macro</span> <span class="fu">sayhello</span>(name)</span>
<span id="cb17-2"><a href="Julia.html#cb17-2" tabindex="-1"></a>  <span class="op">:</span>(<span class="fu">println</span>(<span class="st">&quot;Hello,&quot;</span>,<span class="op">$</span>name)) <span class="co"># 注意括号的使用</span></span>
<span id="cb17-3"><a href="Julia.html#cb17-3" tabindex="-1"></a><span class="kw">end</span></span></code></pre></div>
<ul>
<li>变量赋值</li>
</ul>
<div class="sourceCode" id="cb18"><pre class="sourceCode julia"><code class="sourceCode julia"><span id="cb18-1"><a href="Julia.html#cb18-1" tabindex="-1"></a>a,b,c <span class="op">=</span> <span class="fl">1</span>,<span class="ch">&#39;a&#39;</span>,<span class="fl">3</span> </span></code></pre></div>
<ul>
<li>一些函数可以作用于矩阵，如果在其后加个点意味着它作用于矩阵的元素，如</li>
</ul>
<div class="sourceCode" id="cb19"><pre class="sourceCode julia"><code class="sourceCode julia"><span id="cb19-1"><a href="Julia.html#cb19-1" tabindex="-1"></a>x1 <span class="op">=</span> <span class="fu">randn</span>(<span class="fl">6</span>,<span class="fl">4</span>)</span>
<span id="cb19-2"><a href="Julia.html#cb19-2" tabindex="-1"></a>x2 <span class="op">=</span> <span class="fu">round</span>.(x1)</span></code></pre></div>
<ul>
<li>创建矩阵的方式，和matlab有许多共通之处。拼接也是类似的。</li>
</ul>
<div class="sourceCode" id="cb20"><pre class="sourceCode julia"><code class="sourceCode julia"><span id="cb20-1"><a href="Julia.html#cb20-1" tabindex="-1"></a>A <span class="op">=</span> [<span class="fl">1</span> <span class="fl">2</span> <span class="fl">3</span> <span class="fl">4</span>;<span class="fl">5</span> <span class="fl">6</span> <span class="fl">7</span> <span class="fl">8</span> <span class="fl">9</span>];</span>
<span id="cb20-2"><a href="Julia.html#cb20-2" tabindex="-1"></a>A <span class="op">=</span> <span class="fu">randn</span>(<span class="fl">10</span>,<span class="fl">8</span>) <span class="co"># 10行8列的正态分布矩阵</span></span>
<span id="cb20-3"><a href="Julia.html#cb20-3" tabindex="-1"></a>A <span class="op">=</span> ones（<span class="fl">6</span>，<span class="fl">5</span>）</span></code></pre></div>
<ul>
<li><code>include</code>类似于R的<code>source</code>.</li>
</ul>

</div>
</div>
            </section>

          </div>
        </div>
      </div>
<a href="Maple.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="Stata.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
    </div>
  </div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"whatsapp": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": null,
"text": null
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": ["CBook.pdf"],
"search": {
"engine": "fuse",
"options": null
},
"toc": {
"collapse": "subsection"
}
});
});
</script>

<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    var src = "true";
    if (src === "" || src === "true") src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/latest.js?config=TeX-MML-AM_CHTML";
    if (location.protocol !== "file:")
      if (/^https?:/.test(src))
        src = src.replace(/^https?:/, '');
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>
</body>

</html>
